package build_resource

import (
	"go_server/game_server/api/service"
	"go_server/game_server/constants"
	"go_server/game_server/event_manager"
	"go_server/game_server/event_manager/event_data"
	"go_server/zinx/zlog"
)

type BuildResourceService struct {
	service.AbsService

	BuildResourceStates  *BuildResourceStatesApi
	BuildResourceCollect *BuildResourceCollectApi

	eventMethods map[event_data.EventType]func(event event_data.IEvent)
}

const (
	START_COLLECT_RESOURCE = 1 // 机器人开始采集状态
	STOP_COLLECT_RESOURCE  = 2 // 机器人停止采集状态
	COLLECT_RESOURCE       = 3 // 采集操作
)

var (
	ServiceObj *BuildResourceService

	cfgBuildIds = []int32{ // 初始一级配置的资源建筑id集合
		constants.FARM_BUILD_ID,
		constants.QUARRY_BUILD_ID,
		constants.SMELTER_BUILD_ID,
		constants.REFINERY_BUILD_ID,
	}
)

func init() {
	ServiceObj = &BuildResourceService{
		BuildResourceStates:  &BuildResourceStatesApi{},
		BuildResourceCollect: &BuildResourceCollectApi{},

		eventMethods: make(map[event_data.EventType]func(event event_data.IEvent)),
	}

	event_manager.EventManagerObj.AddServiceEvent(event_data.LoginEvent, onLoginEvent, ServiceObj) //监听登录事件，测试
}

func (s *BuildResourceService) GetModuleName() string {
	return "build_resource"
}

func (s *BuildResourceService) GetEventHandleFunc(eventType event_data.EventType) (func(event event_data.IEvent), bool) {
	eventFunc, ok := s.eventMethods[eventType]
	if !ok {
		zlog.Errorf("GetEventHandleFunc Err!!! method not found!! eventType: %d", eventType)
		return nil, false
	}
	return eventFunc, true
}

func (s *BuildResourceService) GetEventMap() map[event_data.EventType]func(event event_data.IEvent) {
	return s.eventMethods
}

func onLoginEvent(event event_data.IEvent) {
	/*conn := event.GetRoleConn()
	roleId, ok := event.GetRoleId()
	if !ok {
		return
	}

	if roleId == 200052 {
		ServiceObj.BuildResourceCollect.TestHandle(roleId, conn)
	}*/
}
